<!DOCTYPE html >
<html>
<head>
    <meta charset="UTF-8">
    <title>网站配置</title>
        <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="/static/home/bootstrap/css/bootstrap.min.css">
</head>
<body>
<div class='container' style="margin-bottom: 50px;margin-top: 20px">
    <div class="row">
        <div class='col-md-8'>
            <form id="user_form" action="/config/option/updateoption" role="form">
                <div class="form-group">
                    <div class="alert alert-warning" id='warning-block'>
                        <p>修改网站配置</p>
                    </div>
                    <div>
                        <label for='title'>网站标题</label>
                        <input type="text" class="form-control" name="title" id="title"
                               placeholder="请输入网站标题" required="required" value="{{.config.Title}}">
                    </div>
                    <div id="titleTip"></div>
                    <div>
                        <label for='slogan'>漂移通知</label>
                        <input type="text" class="form-control" name="slogan" id="slogan"
                               placeholder="请输入通知"  value="{{.config.Slogan}}">
                    </div>
                </div>
                <div class="form-group">
                    <div>
                        <label for="content">网站描述</label>
                        <textarea  class="form-control" rows="10" name="content" id="content">{{.config.Content}}</textarea>
                    </div>
                </div>

                <div class="form-group">
                    <div>
                        <label for="address">网站头部</label>
                        <textarea class="form-control" rows="10" name="address" id="address">{{.config.Address}}</textarea>
                    </div>
                </div>

                <div class="form-group">
                    <div>
                        <label for='phone'>联系电话</label>
                        <input type="text" class="form-control" name="phone" id="phone"
                               placeholder="请输入手机或电话"  value="{{.config.Phone}}">
                    </div>
                </div>
                <div class="form-group">
                    <div>
                        <label for='webinfo'>首页配置（非专业人士勿改）</label>
                        <textarea class="form-control" rows="10" name="webinfo" id="webinfo"
                                  required="required">{{.config.Webinfo}}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <div>
                        <label for='code1'>跟帖代码</label>
                        <textarea class="form-control" rows="5" name="code1" id="code1">{{.config.Code1}}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <div>
                        <label for='code2'>统计代码</label>
                        <textarea class="form-control" rows="5" name="code2" id="code2">{{.config.Code2}}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <div>
                        <label for='code3'>网站脚部</label>
                        <textarea class="form-control" rows="10" name="code3" id="code3">{{.config.Code3}}</textarea>
                    </div>
                </div>
                <div id='uploadlogo'></div>

                <div class="form-group">
                    <div>
                        <button type="submit" class="btn btn-default">修改</button>
                    </div>
                </div>
            </form>
        </div>
        <div class='col-md-4'>
            <div align="center">
                <img src="{{.config.Photo}}" id='logoimg' class="am-img-responsive" alt="图片"
                     style="border:1px red solid;height: 260px; width: 260px;"/>

                <p>请上传格式为.png .jpg .jpeg的图片。</p>

                <p>上传完毕后需要点击左边曾加按钮才能生效。</p>

                <div id='uploadphotoconfirm' style='color:red'></div>
                <div>
                    <button type="submit" class="btn btn-default" id='upload_button'>上传Logo</button>
                </div>
                <div class="btn btn-success"><a id='lookphoto' href="{{.config.Photo}}"
                                                target="_blank">查看Logo</a>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="/static/admin/formvalidator4.1.3/jquery-1.7.2.min.js"></script>
<script src="/static/admin/formvalidator4.1.3/formValidator-4.1.3.min.js" type="text/javascript"></script>
<script src="/static/admin/formvalidator4.1.3/formValidatorRegex.js" type="text/javascript"></script>
<script src="/static/tool/ajaxupload.js"></script>
<link rel="stylesheet" href="/static/admin/kindeditor/themes/default/default.css"/>
<link rel="stylesheet" href="/static/admin/kindeditor/themes/simple/simple.css"/>
<script charset="utf-8" src="/static/admin/kindeditor/kindeditor-all-min.js"></script>
<script charset="utf-8" src="/static/admin/kindeditor/lang/zh-CN.js"></script>
<script src="/static/tool/ajaxupload.js"></script>
<script type="text/javascript">
    KindEditor.ready(function (K) {
        var option = {
            themeType: 'simple',
            cssPath: '/static/admin/kindeditor/plugins/code/prettify.css',
            uploadJson: '/public/file/upload',
            fileManagerJson: '/public/file/filemanage',
            allowFileManager: false
        };
        var editor = K.create('textarea[name="content"]', option);
       /* var editor1 = K.create('textarea[name="address"]', option);*/
         var editor2 = K.create('textarea[name="code3"]', option);
        editor.sync();
      /*  editor1.sync();*/
        editor2.sync();
        $.formValidator.initConfig({
            formID: "user_form", submitOnce: true,
            onSuccess: function () {
                var registerForm = $("#user_form");
                $.post(registerForm.attr("action"), registerForm.serialize(), function (data) {
                    alert(data.info)
                    $('#warning-block p').html('<strong>警告！</strong>' + data.info);
                    return;
                });
            }
        });


        $("#title").formValidator({onShowText: "请输入网站标题"})
                .inputValidator({
                    min: 2,
                    max: 100,
                    onError: "标题2~100个字符",
                    empty: {leftEmpty: false, rightEmpty: false, emptyError: "标题两边不能为空"}
                });



     /*   $("#phone").formValidator({onFocus: "如0768-8888888或11位手机号码", onCorrect: "谢谢你的合作"})
                .regexValidator({regExp: ["tel", "mobile"], dataType: "enum", onError: "你输入的手机或电话格式不正确"});*/

    });

</script>
<script>
    $(function () {
        var button = $('#upload_button'), interval;
        var confirmdiv = $('#uploadphotoconfirm');
        var fileType = "ptic", fileNum = "one";
        new AjaxUpload(button, {
            action: "/public/file/upload?dir=image",
            name: 'imgFile',
            responseType: 'json',
            onSubmit: function (file, ext) {
                if (fileType == "pic") {
                    if (ext && /^(jpg|png|jpeg|gif)$/.test(ext)) {
                        this.setData({
                            'info': '文件类型为图片'
                        });
                    } else {
                        confirmdiv.text('文件格式错误，请上传格式为.png .jpg .jpeg 的图片');
                        return false;
                    }
                }

                confirmdiv.text('文件上传中');

                if (fileNum == 'one')
                    this.disable();

                interval = window.setInterval(function () {
                    var text = confirmdiv.text();
                    if (text.length <= 5) {
                        confirmdiv.text('文件上传中...');
                    } else {
                        confirmdiv.text('文件上传中');
                    }
                }, 200);
            },
            onComplete: function (file, response) {
                if (response.error == 1) {
                    confirmdiv.text(response.message);
                } else {
                    confirmdiv.text("上传完成");
                    $("#logoimg").attr("src", response.url);
                    $('#lookphoto').attr("href", response.url);
                    $("#uploadlogo").html("<input hidden='hidden' type='hidden'  name='photo' value='" + response.url + "'>");
                }

                window.clearInterval(interval);
                this.enable();
            }
        });
    });

</script>
</body>
</html>
